package com.focus.xyz.main.cases;

import com.focus.xyz.core.common.annotation.Task;
import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.common.listeners.TC;
import com.focus.xyz.core.common.webdriver.DriverFactory;
import com.focus.xyz.core.utils.ProcessUtil;
import com.focus.xyz.main.pages.ApolloHomePage;
import com.focus.xyz.main.pages.ApolloLoginPage;
import com.focus.xyz.main.pages.ApolloMemCenterPage;
import com.focus.xyz.main.pages.ApolloMemberInfoPage;
import com.focus.xyz.union.action.KeyWordAction;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

/**
 * Created by chenmeng on 2016/7/27.
 */
public class AddContactTest extends TC{
    private WebDriver driver;
    private Action action;

    @Parameters({"nodeUrl","browser"})
    @BeforeMethod(alwaysRun = true)
    public void setUp(String nodeUrl,String browser) throws Exception {
        driver = DriverFactory.getDriver(nodeUrl).getBrowser(browser);
        super.init(driver);
        action = new Action(driver);
    }


    @Parameters({"browser"})
    @AfterMethod(alwaysRun = true)
    public void tearDown(String browser) {
        try{
            driver.quit();
        }catch (Exception e){
            ProcessUtil.closeBrowser(browser);
        }finally {

        }
    }

    @Task(taskName = {"TEST_Apollo.sql"},paras = {"param0=subxx"})
    @Test(description = "新增联系人")
    public void addContact() throws Exception{
        /*打开主站首页，点击登录*/
        ApolloHomePage homePage = new ApolloHomePage(driver,action);
        homePage.openMainPage();
        homePage.clickLoginBtn();
        ApolloLoginPage loginPage = new ApolloLoginPage(driver,action);
        loginPage.login("18651809616","He11o123");
        ApolloMemCenterPage memPage = new ApolloMemCenterPage(driver,action);
        memPage.openMenu("常用联系人");
        action.pause(2000);
        action.assertStringTrue("陈铭哲");
        action.assertStringFalse("陈铭哲");
        ApolloMemberInfoPage infoPage = new ApolloMemberInfoPage(driver,action);
        infoPage.clickAddLink();
        action.pause(2000);
    }
}
